@extends('admin::layouts.master')
@section('content')

    @component('components.caozuo',['title'=>'给['.$role['title'].']设置角色','url'=>'/admin/assignPermission/'.$role['id'],'submit'=>'onsubmit="return tijiao()"'])
        @slot('nav')
            <li class="nav-item"><a href="{{route('role.index')}}" class="nav-link">角色列表</a></li>
            <li class="nav-item"><a href="#" class="nav-link active">权限设置</a>
            </li>
            @endslot
        @slot('body')
            <div class="col-lg-12">
                <div class="card card-full-warning card-border-color">
                    <div class="card-header"><h2>【权限设置】==>>>>{{$role['title']}}</h2></div>
                    @foreach($module as $v)
                        @foreach($v['rules'] as $vv)
                            <div class="card-body">
                                <div class="form-group row pt-1 pb-1 ">
                                    <label class="col-12 col-sm-3 col-form-label  text-sm-right">{{$vv['group']}}</label>
                                    <div class="col-12 col-sm-8 col-lg-6 form-check mt-2">
                                        @foreach($vv['permissions'] as $vvv)
                                            <label class="custom-control custom-checkbox custom-control-inline">
                                                <input type="checkbox" class="custom-control-input quanxian" name="name[]" {{$role->hasPermissionTo($vvv['name']) ? 'checked' : ''}} value="{{$vvv['name']}}">
                                                <span class="custom-control-label custom-control-color">{{$vvv['title']}}</span>
                                            </label>
                                        @endforeach
                                    </div>
                                </div>
                            </div>
                        @endforeach
                    @endforeach
                    <div class="col-lg-12 text-center">
                        <button type="submit" class="btn btn-rounded  btn-success">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="{{route('role.index')}}" class="btn btn-rounded  btn-success">返回</a>
                    </div>

                </div>

            </div>
            @endslot

        @endcomponent


    @endsection
@section('script')
    <script>
        function tijiao() {
            //定义一个变量
            var a = 0;
            $('.quanxian').each(function (k,v) {
                if (v.checked){
                    a = 1;
                }
            })
            if (a == 0){
                alert('请勾选至少一个权限进行分配');
                return false;
            }
            //如果勾选了至少一个,a就等于1,就进行form表单的提交
            return true;
        }
    </script>
@endsection